package com.qqt.csr.file.service.impl;

import com.google.common.collect.Lists;
import com.obs.services.ObsClient;
import com.obs.services.model.HeaderResponse;
import com.qqt.csr.file.config.HuaWeiObsProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.List;

public class AbstractHWOBSService {
    @Value("${file.upload.domainUrl}")
    protected String domainUrl;
    @Value("${file.upload.rootFolder}")
    protected String rootFolder;
    @Autowired
    protected HuaWeiObsProperties huaWeiObsProperties;
    @Autowired
    protected ObsClient obsClient;

    /**
     * 判断请求是否成功
     *
     * @param headerResponse
     * @return
     */
    protected boolean isRequestSuccess(HeaderResponse headerResponse) {
        List<Integer> successStatusCode = Lists.newArrayList(200, 201, 202, 203, 204, 205, 206);
        return headerResponse != null && successStatusCode.contains(headerResponse.getStatusCode());
    }

    /**
     * 获取区域
     *
     * @param endPoint
     * @return
     */
    protected String getRegion(String endPoint) {
        String substring = endPoint.substring(endPoint.indexOf(".") + 1);
        return substring.substring(0, substring.indexOf("."));
    }
}
